using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Mpi.Common
{
    /// <summary>
    /// Helper class to for XML lexical types
    /// </summary>
    public static class XmlLexicalType
    {
        /// <summary>
        /// Converts a string to the W3C standardized XML data type token
        /// </summary>
        /// <param name="str">A abritary input string</param>
        /// <returns>A string repraesenting the XML datatype 'token'</returns>
        public static string ConvertToToken(string str)
        {
            if (String.IsNullOrEmpty(str))
                return str;
            string token;

            token = str;
            token = token.Replace("\t", "");
            token = token.Replace("\r", "");
            token = token.Replace("\n", "");
            token = token.Replace("  ", " ");
            token = token.Trim();

            Regex rex = new Regex(@"\ {2,}");
            token = rex.Replace(token, " ");

            return token;
        }


    }
}
